
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.*;
import java.util.*;

import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;

/**
 * 通行规则api
 */
 
@Api(tags = "AccessRule",description = "通行规则")
@RestController
public class AccessRuleController {
    
    @Autowired
    private AccessRuleDao dao;
   
    /**
     * 获取通行规则集合
     * @return api结果
     */
    @ApiOperation(value = "获取通行规则集合")
    @RequestMapping(value =  "/api/AccessRule/",method = {RequestMethod.GET})
    public ApiResult<List<AccessRule>> get(){
         ApiResult<List<AccessRule>> result=new ApiResult<List<AccessRule>>();
        try 
        {
            List<AccessRule> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取通行规则信息
     * @param id 通行规则ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取通行规则信息")
    @RequestMapping(value =  "/api/AccessRule/{id}",method = {RequestMethod.GET})
    public ApiResult<AccessRule> Get(@PathVariable Long id){
        ApiResult<AccessRule> result=new ApiResult<AccessRule>();
        try
        {
            AccessRule model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 修改通行规则信息
     * @param id 通行规则ID
     * @param model 通行规则信息
     * @return api结果
     */
    @ApiOperation(value = "修改通行规则信息")
    @RequestMapping(value =  "/api/AccessRule/{id}",method = {RequestMethod.PUT})
    public ApiResult<AccessRule> Edit(@PathVariable Long id,@RequestBody AccessRule model){
        ApiResult<AccessRule> result=new ApiResult<AccessRule>();
        try
        {
            model.setAccessRuleId(id);
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 添加通行规则信息
     * @param model 通行规则信息
     * @return api结果
     */
    @ApiOperation(value = "添加通行规则信息")
    @RequestMapping(value =  "/api/AccessRule/",method = {RequestMethod.POST})
    public ApiResult<AccessRule> Add(@RequestBody AccessRule model){
         ApiResult<AccessRule> result=new ApiResult<AccessRule>();
        try
        {
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除通行规则信息
     * @param id 通行规则ID
     * @return api结果
     */
    @ApiOperation(value = "删除通行规则信息")
    @RequestMapping(value =  "/api/AccessRule/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 根据项目ID获取规则信息
     * @param ticketTypeId 票类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据项目ID获取规则信息")
    @RequestMapping(value =  "/api/AccessRule/Project/{projectId}",method = {RequestMethod.GET})
    public ApiResult<List<AccessRule>> Project(@PathVariable String projectId){
        ApiResult<List<AccessRule>> result=new ApiResult<List<AccessRule>>();
        try 
        {
            result.setData( dao.findByProjectId(projectId));
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 根据票类型ID获取规则信息
     * @param ticketTypeId 票类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据票类型ID获取规则信息")
    @RequestMapping(value =  "/api/AccessRule/TicketType/{ticketTypeId}",method = {RequestMethod.GET})
    public ApiResult<List<AccessRule>> TicketTypeId(@PathVariable Long ticketTypeId){
        ApiResult<List<AccessRule>> result=new ApiResult<List<AccessRule>>();
        try 
        {
            result.setData(dao.findByTicketTypeId(ticketTypeId));
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 根据证件类型ID获取规则信息
     * @param documentTypeId 证件类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据证件类型ID获取规则信息")
    @RequestMapping(value =  "/api/AccessRule/DocumentType/{documentTypeId}",method = {RequestMethod.GET})
    public ApiResult<List<AccessRule>> DeleteByDocumentTypeId(@PathVariable Long documentTypeId){
        ApiResult<List<AccessRule>> result=new ApiResult<List<AccessRule>>();
        try 
        {
          result.setData( dao.findByDocumentTypeId(documentTypeId));;
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

